<template>
  <div>
    <van-nav-bar :title="`我的订单`"
                 :fixed=true
                 :border=false
                 @click-left="onClickLeft"
                 left-arrow
                 style="height:2.5rem;color: #FFFFFF" />
    <van-cell></van-cell>
    <van-cell></van-cell>
    <van-empty v-if="orderList==null||orderList.length==0"  description="这里什么都没有" />
    <van-row v-for="item in orderList" :key="item.orderInfo.orderId">
    <van-card
            style="margin-top: 2px"
            :thumb="item.movieImg"
            :price="item.orderInfo.oldPrice">
      <template #title>
        <div>
          {{item.movieName}}
        </div>
      </template>

      <template #num>
        座位数量：{{item.orderInfo.num}}
      </template>

      <template #desc>
        <div>
          订单号：{{ item.orderInfo.orderId }}
<!--          <span style="margin-left: 10px">-->
<!--            订单码：{{item.orderInfo.sn}}-->
<!--          </span>-->
        </div>
        <div>
          {{item.orderInfo.createTime}}
        </div>
      </template>

      <template #tags>
        <van-tag style="margin-left: 1px" v-for="(seat,index) in item.seatInfo" :key="'S'+index" plain type="danger">{{seat}}</van-tag>
      </template>


      <template #num>
        座位数量：{{item.orderInfo.num}}
      </template>
    </van-card>

    </van-row>
  </div>
</template>

<script>
import {getJwtToken} from "@/lib/utils/TokenUtil";
import store from "@/store";
import {orderList} from "@/api/order";

export default {
name: "OrderList",
  beforeRouteEnter (to,from,next) {
    if (getJwtToken()!==''){
      if (store.state.user.isGetInfo){
        console.log(store.state.user.accountInfo.accountId)
        orderList({aid:store.state.user.accountInfo.accountId})
            .then(res=>{
              console.log(res)
              next(vm => vm.setOrderList(res.data))
            })
      }else {
        store.dispatch('GetUserInfo').then(()=>{
          orderList({aid:store.state.user.accountInfo.accountId})
              .then(res=>{
                console.log(res)
                next(vm => vm.setOrderList(res.data))
              })
        })
      }
    }else{
      next('/login')
    }
  },
  data(){
    return{
      orderList:[],
      loading: false,
      finished: false,
    }
  },
  methods:{
    onClickLeft () {
      this.$router.back();
    },
    setOrderList(data){
      this.orderList = data;
    },
  }
}
</script>

<style scoped>

</style>
